package com.patrol.logisticsmanage.ui.canteen;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.launcher.ARouter;
import com.patrol.logisticsmanage.MainActivity;
import com.patrol.logisticsmanage.R;
import com.patrol.logisticsmanage.net.BaseObserver;
import com.patrol.logisticsmanage.net.BaseReponse;
import com.patrol.logisticsmanage.net.BaseRequest;
import com.patrol.logisticsmanage.ui.canteen.utils.ToastUtils;
import com.patrol.logisticsmanage.ui.orders.OrderInfo;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class CanteenFragment extends Fragment {

    Unbinder unbinder;
    @BindView(R.id.card_food)
    CardView cardFood;
    @BindView(R.id.card_satisfaction)
    CardView cardSatisfaction;
    @BindView(R.id.card_advise)
    CardView cardAdvise;
    @BindView(R.id.card_guesthouse)
    CardView cardGuesthouse;
    @BindView(R.id.card_recommend)
    CardView cardRecommend;
    @BindView((R.id.renshu))
    TextView renshu;


    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_canteen, container, false);
        unbinder = ButterKnife.bind(this, root);
        getData();
        return root;
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.card_food, R.id.card_satisfaction, R.id.card_advise, R.id.card_guesthouse,R.id.card_recommend})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.card_food:
                ARouter.getInstance().build("/app/CanteenActivity")
                        .withBoolean("isCanOrder", false).navigation();
                break;
            case R.id.card_satisfaction:
                if (MainActivity.subCampList.size() == 0) {
                    ToastUtils.showToast("地址获取失败，请稍后再试");
                    return;
                }
                ARouter.getInstance().build("/app/WebViewActivity")
                        .withString("url", MainActivity.url1)
                        .withString("title", "满意度调查")
                        .navigation();
                break;
            case R.id.card_advise:
                if (MainActivity.subCampList.size() == 0) {
                    ToastUtils.showToast("地址获取失败，请稍后再试");
                    return;
                }
                ARouter.getInstance().build("/app/WebViewActivity")
                        .withString("url", MainActivity.url2)
                        .withString("title", "服务意见征集")
                        .navigation();
                break;
            case R.id.card_guesthouse:
                ARouter.getInstance().build("/app/CanteenActivity")
                        .withBoolean("isCanOrder", true).navigation();
                break;
            case R.id.card_recommend:
                ARouter.getInstance().build("/app/EditInfoActivity")
                        .navigation();
                break;
        }
    }

    public void getData(){
        BaseRequest.getInstance().getApiServise().queryShitdqrs("0")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<String>(getContext()) {
                    @Override
                    public void onSuccess(BaseReponse<String> baseReponse) {
                        renshu.setText(baseReponse.getResults());
                    }

                    @Override
                    public void onCodeError(BaseReponse tBaseReponse) {
                        tBaseReponse.getCode();
                    }
                    @Override
                    public void onFailure(Throwable e, boolean netWork) throws Exception {
                        e.printStackTrace();
                    }
                });
    }

}